from app.db.models import *
from app.db.base import Base, engine
from sqlalchemy import text

def init_db():
    print("Creating database tables...")
    print(Base.__subclasses__())
    
    # 删除所有现有表（如果需要）
    # Base.metadata.drop_all(engine)
    
    # 创建所有表
    Base.metadata.create_all(engine)
    
    # 验证连接
    with engine.connect() as conn:
        result = conn.execute(text("SELECT version();"))
        print(f"Connected to PostgreSQL: {result.scalar()}")

if __name__ == "__main__":
    init_db()
